package com.hexorld.layer;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;

import com.hexorld.core.HVObject;
import com.hexorld.core.UpdateFlag;

public abstract class Layer {
	protected ArrayList<HVObject> mChild = null;
	protected Layer mParent = null;
	protected int mWidth, mHeight;
	public int Z = 0;
	protected Context mContext = null;
	protected boolean mbVisible = true;
	public Layer(Context context, int width, int height, int z){
		mContext = context;
		mWidth = width;
		mHeight = height;
		Z = z;
		mChild = new ArrayList<HVObject>();
	}
	
	public void add(HVObject vl){
		if(mChild != null && vl != null)
		{
			mChild.add(vl);
		}
	}
	
	public void remove(HVObject vl){
		if(mChild != null && mChild.indexOf(vl) != -1)
			mChild.remove(vl);
	}
	
	public void clearChildLayers(){
		if(mChild != null)
			mChild.clear();
	}
	
	
	public void setParent(Layer vl){
		mParent = vl;
	}
	
	public Layer getParent(){
		return mParent;
	}

	public void draw(Canvas canvas){
		for(HVObject obj : mChild)
			obj.draw(canvas);
	}
	
	public void update(UpdateFlag updateFlag){
		for(HVObject obj : mChild)
			obj.update(updateFlag);
	}
	
	public boolean onTouchEvent(MotionEvent event){
		
		return false;
	}
}
